package cn.gs.common.handle;

import cn.gs.common.dto.R;
import cn.gs.common.exception.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletResponse;

/** 处理全局异常信息
 * @author gs
 * @date 2020/1/9
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandle {


    @ExceptionHandler(GlobalException.class)
    public R globException(GlobalException e, HttpServletResponse httpServletResponse){
        log.error(e.getMessage());
        int status = httpServletResponse.getStatus();
        return new R(status,e.getMessage());
    }



}
